home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performSubdivCreate.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  11.2 KB  |  460 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //  Alias|Wavefront Script File
  18. //  MODIFY THIS AT YOUR OWN RISK
  19. //
  20. //  Creation Date:  12 March, 1999
  21. //  Author:         nrohm
  22. //
  23. //  Description:
  24. //        Option box for subdivision surface create
  25. //      Create a subdivision surface from a polygon or a nurbs surface.
  26. //
  27.  
  28. //
  29. //  Procedure Name:
  30. //      setOptionVars
  31. //
  32. //  Description:
  33. //        Initialize the option values.
  34. //
  35. //  Input Arguments:
  36. //        Whether to set the options to default values.
  37. //
  38. //  Return Value:
  39. //      None.
  40. //
  41. //  Note:
  42. //
  43. global proc subdivCreateVisibility( string $parent, int $mode, int $keep )
  44. {
  45.     setParent $parent;
  46.     if( ($mode < 0) && ($keep < 0) ) {
  47.         $mode = `radioButtonGrp -q -sl subdivCreateOrigObject`;
  48.         $keep = `checkBoxGrp -q -v1 subdivCreateKeepOrigObject`;
  49.     }
  50.  
  51.     switch( $mode ) {
  52.       case 1:
  53.         checkBoxGrp -e -en true subdivCreateKeepOrigObject;
  54.         break;
  55.       case 2:
  56.         checkBoxGrp -e -en false subdivCreateKeepOrigObject;
  57.         break;
  58.       default:
  59.         break;
  60.     }
  61.  
  62.     if( $keep >= 0 ) {
  63.         if( $keep ) {
  64.             radioButtonGrp -e -en true subdivCreateOrigObject;
  65.         }
  66.         else {
  67.             radioButtonGrp -e -en false subdivCreateOrigObject;
  68.         }
  69.     }
  70. }
  71.  
  72. proc setOptionVars(int $forceFactorySettings)
  73. {
  74.  
  75.     //    
  76.     //  Original Object
  77.     //    
  78.     if ($forceFactorySettings || 
  79.         !`optionVar -exists subdivCreateOrigObject`) {
  80.         optionVar -intValue subdivCreateOrigObject 1; 
  81.     }
  82.  
  83.     //    Maximum Number Polygons that input mesh can have
  84.     //    
  85.     if ($forceFactorySettings ||
  86.         !`optionVar -exists subdivCreateMaxPolygons`) {
  87.         optionVar -intValue subdivCreateMaxPolygons 1000;
  88.     }
  89.  
  90.     //    Maximum Edges Per Vertex (valence)
  91.     //    
  92.     if ($forceFactorySettings ||
  93.         !`optionVar -exists subdivCreateMaxEdgesPerVert`) {
  94.         optionVar -intValue subdivCreateMaxEdgesPerVert 32;
  95.     }
  96. }
  97.  
  98.  
  99. //
  100. //  Procedure Name:
  101. //      subdivCreateSetup
  102. //
  103. //  Description:
  104. //        Update the state of the option box UI to reflect the option values.
  105. //
  106. //  Input Arguments:
  107. //      parent               - Top level parent layout of the option box UI.
  108. //                             Required so that UI object names can be 
  109. //                             successfully resolved.
  110. //
  111. //    forceFactorySettings - Whether the option values should be set to
  112. //                             default values.
  113. //
  114. //  Return Value:
  115. //      None.
  116. //
  117. global proc subdivCreateSetup(string $parent, int $forceFactorySettings)
  118. {
  119.     int $method;
  120.  
  121.     //    Retrieve the option settings
  122.     //
  123.     setOptionVars($forceFactorySettings);
  124.  
  125.     setParent $parent;
  126.  
  127.     //    Query the optionVar's and set the values into the controls.
  128.  
  129.     //  Original Object
  130.     //
  131.     int $origObject = `optionVar -query subdivCreateOrigObject`;
  132.     switch( $origObject ) {
  133.       case 0:
  134.         radioButtonGrp -e -select 2 subdivCreateOrigObject;
  135.         checkBoxGrp -e -v1 0 subdivCreateKeepOrigObject;
  136.         break;
  137.       case 1:
  138.       default:
  139.         radioButtonGrp -e -select 1 subdivCreateOrigObject;
  140.         checkBoxGrp -e -v1 0 subdivCreateKeepOrigObject;
  141.         break;
  142.       case 2:
  143.         radioButtonGrp -e -select 2 subdivCreateOrigObject;
  144.         checkBoxGrp -e -v1 1 subdivCreateKeepOrigObject;
  145.         break;
  146.       case 3:
  147.         radioButtonGrp -e -select 1 subdivCreateOrigObject;
  148.         checkBoxGrp -e -v1 1 subdivCreateKeepOrigObject;
  149.         break;
  150.     }
  151.  
  152.     // Maximum Number Polygons that input mesh can have
  153.     //
  154.     intSliderGrp -e 
  155.         -value `optionVar -query subdivCreateMaxPolygons`
  156.         subdivCreateMaxPolygons;
  157.  
  158.     // Maximum Edges Per Vertex (valence)
  159.     //
  160.     intSliderGrp -e 
  161.         -value `optionVar -query subdivCreateMaxEdgesPerVert`
  162.         subdivCreateMaxEdgesPerVert;
  163.  
  164.     subdivCreateVisibility( $parent, -1, -1 );
  165. }
  166.  
  167. //
  168. //  Procedure Name:
  169. //      subdivCreateCallback
  170. //
  171. //  Description:
  172. //        Update the option values with the current state of the option box UI.
  173. //
  174. //  Input Arguments:
  175. //      parent - Top level parent layout of the option box UI.  Required so
  176. //               that UI object names can be successfully resolved.
  177. //
  178. //    doIt   - Whether the command should execute.
  179. //
  180. //  Return Value:
  181. //      None.
  182. //
  183. global proc subdivCreateCallback(string $parent, int $doIt)
  184. {
  185.     setParent $parent;
  186.  
  187.     //    Set the optionVar's from the control values, and then
  188.     //    perform the command.
  189.  
  190.     //  Original Object
  191.     //    
  192.     int $origObject = 1;
  193.     int $radioOrig = `radioButtonGrp -query -select subdivCreateOrigObject`;
  194.     if( 1 == $radioOrig ) {
  195.         if( `checkBoxGrp -q -v1 subdivCreateKeepOrigObject` ) {
  196.             $origObject = 3;
  197.         }
  198.         else {
  199.             $origObject = 1;
  200.         }
  201.     }
  202.     else {
  203.         if( `checkBoxGrp -q -v1 subdivCreateKeepOrigObject` ) {
  204.             $origObject = 2;
  205.         }
  206.         else {
  207.             $origObject = 0;
  208.         }
  209.     }
  210.     optionVar -intValue subdivCreateOrigObject $origObject;
  211.  
  212.     //    Maximum Number Polygons that input mesh can have
  213.     //    
  214.     optionVar -intValue subdivCreateMaxPolygons
  215.         `intSliderGrp -query -value subdivCreateMaxPolygons`;
  216.  
  217.     //    Maximum Edges Per Vertex (valence)
  218.     //    
  219.     optionVar -intValue subdivCreateMaxEdgesPerVert
  220.         `intSliderGrp -query -value subdivCreateMaxEdgesPerVert`;
  221.  
  222.     if ($doIt) {
  223.         performSubdivCreate 0; 
  224.         addToRecentCommandQueue "performSubdivCreate 0" "Create Subdiv";
  225.     }
  226. }
  227.  
  228. //
  229. //  Procedure Name:
  230. //      subdivCreateOptions
  231. //
  232. //  Description:
  233. //        Construct the option box UI.  Involves accessing the standard option
  234. //        box and customizing the UI accordingly.
  235. //
  236. //  Input Arguments:
  237. //      None.
  238. //
  239. //  Return Value:
  240. //      None.
  241. //
  242. proc subdivCreateOptions()
  243. {
  244.     //    Name of the command for this option box.
  245.     //
  246.     string $commandName = "subdivCreate";
  247.  
  248.     //    Build the option box actions.
  249.     //
  250.     string $callback = ($commandName + "Callback");
  251.     string $setup = ($commandName + "Setup");
  252.  
  253.     //    STEP 1:  Get the option box.
  254.     //    ============================
  255.     //
  256.     string $layout = getOptionBox();
  257.     setParent $layout;
  258.     
  259.     //    STEP 2:  Pass the command name to the option box.
  260.     //    =================================================
  261.     //
  262.     setOptionBoxCommandName($commandName);
  263.     
  264.     //    STEP 3:  Activate the default UI template.
  265.     //    ==========================================
  266.     //
  267.     setUITemplate -pushTemplate DefaultTemplate;
  268.  
  269.     //    STEP 4: Create option box contents.
  270.     //    ===================================
  271.     //    
  272.     
  273.     //    Turn on the wait cursor.
  274.     //
  275.     waitCursor -state 1;
  276.  
  277.     tabLayout -tabsVisible 0 -scrollable 1;
  278.     
  279.     string $parent = `columnLayout -adjustableColumn 1`;
  280.     
  281.     //    Maximum Number Polygons that input mesh can have
  282.     //    
  283.     intSliderGrp -label "Maximum Base Mesh Faces"
  284.         -min 1 -max 10000 -fmx 100000
  285.         subdivCreateMaxPolygons;
  286.  
  287.     //    Maximum Edges Per Vertex (valence)
  288.     //    
  289.     intSliderGrp -label "Maximum Edges Per Vertex"
  290.         -min 2 -max 50 -fmx 255
  291.         subdivCreateMaxEdgesPerVert;
  292.  
  293.      //    Original Object
  294.     //
  295.       radioButtonGrp 
  296.           -numberOfRadioButtons 2
  297.           -label "Subdivision Surface Mode"
  298.           -l1 "Standard (no history)"
  299.         -l2 "Proxy Object"
  300.         -on1( "subdivCreateVisibility " + $parent + " 1 -1")
  301.         -on2( "subdivCreateVisibility " + $parent + " 2 -1")
  302.           subdivCreateOrigObject;
  303.  
  304.     checkBoxGrp
  305.         -ncb 1
  306.         -label ""
  307.         -label1 "Keep Original"
  308.         -of1( "subdivCreateVisibility " + $parent + " -1 0")
  309.         -on1( "subdivCreateVisibility " + $parent + " -1 1")
  310.         subdivCreateKeepOrigObject;
  311.  
  312.     //    Turn off the wait cursor.
  313.     //
  314.     waitCursor -state 0;
  315.     
  316.     //    Step 5: Deactivate the default UI template.
  317.     //    ===========================================
  318.     //
  319.     setUITemplate -popTemplate;
  320.  
  321.     //    Step 6: Customize the buttons.  
  322.     //    ==============================
  323.     //
  324.  
  325.     //    'Apply' button.
  326.     //
  327.     string $applyBtn = getOptionBoxApplyBtn();
  328.     button -e -l "Create"
  329.         -command ($callback + " " + $parent + " " + 1)
  330.         $applyBtn;
  331.  
  332.     //    'Save' button.
  333.     //
  334.     string $saveBtn = getOptionBoxSaveBtn();
  335.     button -e 
  336.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  337.         $saveBtn;
  338.  
  339.     //    'Reset' button.
  340.     //
  341.     string $resetBtn = getOptionBoxResetBtn();
  342.     button -e 
  343.         -command ($setup + " " + $parent + " " + 1)
  344.         $resetBtn;
  345.  
  346.     //    Step 7: Set the option box title.
  347.     //    =================================
  348.     //
  349.     setOptionBoxTitle("Convert To Subdiv Options");
  350.  
  351.     //    Step 8: Customize the 'Help' menu item text.
  352.     //    ============================================
  353.     //
  354.     setOptionBoxHelpTag( "ConvertToSubdiv" );
  355.  
  356.     //    Step 9: Set the current values of the option box.
  357.     //    =================================================
  358.     //
  359.     eval (($setup + " " + $parent + " " + 0));    
  360.     
  361.     //    Step 10: Show the option box.
  362.     //    =============================
  363.     //
  364.     showOptionBox();
  365. }
  366.  
  367. //
  368. //  Procedure Name:
  369. //      subdivCreateHelp
  370. //
  371. //  Description:
  372. //        Return a short description about this command.
  373. //
  374. //  Input Arguments:
  375. //      None.
  376. //
  377. //  Return Value:
  378. //      string.
  379. //
  380. proc string subdivCreateHelp()
  381. {
  382.     return 
  383.     "  Command: subdivCreate - create a subdivision surface from a poly or nurbs surface.\n" +
  384.     "Selection: Polygon or nurbs surfaces.";
  385. }
  386.  
  387. //
  388. //  Procedure Name:
  389. //      assembleCmd
  390. //
  391. //  Description:
  392. //        Construct the command that will apply the option box values.
  393. //
  394. //  Input Arguments:
  395. //      None.
  396. //
  397. proc string assembleCmd()
  398. {
  399.  
  400.     setOptionVars(false);
  401.  
  402.     int $origObject =  `optionVar -query subdivCreateOrigObject`;
  403.     int $doHistory = `constructionHistory -q -tgl`;
  404.     int $maxPolys   =  `optionVar -query subdivCreateMaxPolygons`;
  405.     int $maxEdgesPerVert =  `optionVar -query subdivCreateMaxEdgesPerVert`;
  406.  
  407.     string $version = "\"2\"";
  408.     string $cmd = "doSubdivCreate";
  409.     $cmd = $cmd + "( ";
  410.     $cmd = $cmd + $version;
  411.     $cmd = $cmd + ", { \"" ;
  412.     $cmd = $cmd + $origObject;
  413.     $cmd = $cmd + "\",\"";
  414.     $cmd = $cmd + $doHistory;
  415.     $cmd = $cmd + "\",\"";
  416.     $cmd = $cmd + $maxPolys;
  417.     $cmd = $cmd + "\",\"";
  418.     $cmd = $cmd + $maxEdgesPerVert;
  419.     $cmd = $cmd + "\"} )";
  420.  
  421.     return $cmd;
  422. }
  423.  
  424. //
  425. //  Procedure Name:
  426. //      performSubdivCreate
  427. //
  428. //  Description:
  429. //        Perform the performSubdivCreate command using the corresponding 
  430. //        option values.  This procedure will also show the option box
  431. //        window if necessary as well as construct the command string
  432. //        that will invoke the performSubdivCreate command with the current
  433. //        option box values.
  434. //
  435. //  Input Arguments:
  436. //      0 - Execute the command.
  437. //      1 - Show the option box dialog.
  438. //      2 - Return the command.
  439. //
  440. global proc string performSubdivCreate(int $action)
  441. {
  442.     string $cmd = "";
  443.  
  444.     switch ($action) {
  445.       case 0:
  446.         $cmd = assembleCmd ();
  447.         eval($cmd);
  448.         break;
  449.  
  450.       case 1:
  451.         subdivCreateOptions ();
  452.         break;
  453.  
  454.       case 2:
  455.         $cmd = assembleCmd ();
  456.         break;
  457.     }
  458.     return $cmd;
  459. }
  460.